﻿using System.Collections.Generic;

namespace System.Windows.Forms
{
    static public class Ex_Controls
    {
        static Dictionary<Control, bool> form_resizing = new Dictionary<Control, bool>();
        static public void SetOnSizeChanged(this Form control, Action<object, EventArgs> call)
        {
            control.ResizeBegin += (s, e) =>
            {
                form_resizing[control] = true;
            };
            control.ResizeEnd += (s, e) =>
            {
                form_resizing.Remove(control);
                call(s, e);
            };
            control.SizeChanged += (s, e) =>
            {
                if (form_resizing.ContainsKey(control))
                    return;
                call(s, e);
            };
        }
        static public void SetOnTextEdited(this TextBox text, Action<object, EventArgs> call)
        {
            text.LostFocus += (s, e) =>
            {
                call(s, e);
            };
            text.KeyDown += (s, e) =>
            {
                if (e.KeyCode == Keys.Enter)
                {
                    call(s, e);
                    e.SuppressKeyPress = true;
                }
            };
        }
    }

}
